package com.fbv.backingbean;

import java.util.List;

import javax.faces.application.Application;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 * @author fsn
 *
 */
public class HelloBean {
	private int numControls;
	private HtmlPanelGrid controlPanel;
	
	/**
	 * @return the controlPanel
	 */
	public HtmlPanelGrid getControlPanel() {
		return controlPanel;
	}
	/**
	 * @param controlPanel the controlPanel to set
	 */
	public void setControlPanel(HtmlPanelGrid controlPanel) {
		this.controlPanel = controlPanel;
	}
	/**
	 * @return the numControls
	 */
	public int getNumControls() {
		return numControls;
	}
	/**
	 * @param numControls the numControls to set
	 */
	public void setNumControls(int numControls) {
		this.numControls = numControls;
	}
	
	public void addControls(ActionEvent actionEvent){
		Application application = FacesContext.getCurrentInstance().getApplication();
		List children = controlPanel.getChildren();
		children.clear();
		for(int count = 0; count < numControls; count++){
			HtmlOutputText output = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
			output.setValue(" " + count + " ");
			output.setStyle("color: blue");
			children.add(output);
		}
	}
	
	public String goodbye(){
		return "success";
	}
}
